package cn.csg.iotplatform.module.system.dal.mysql.logger;

import cn.csg.iotplatform.framework.common.pojo.PageResult;
import cn.csg.iotplatform.framework.mybatis.core.mapper.BaseMapperX;
import cn.csg.iotplatform.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.csg.iotplatform.module.system.controller.admin.logger.vo.loginlog.SystemLogPageReqVO;
import cn.csg.iotplatform.module.system.dal.dataobject.logger.GatewayLogDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

@Mapper
public interface GatewayLogMapper extends BaseMapperX<GatewayLogDO> {

    default PageResult<GatewayLogDO> selectPage(SystemLogPageReqVO reqVO) {
        LambdaQueryWrapperX<GatewayLogDO> query = new LambdaQueryWrapperX<GatewayLogDO>()
                .likeIfPresent(GatewayLogDO::getIp, reqVO.getUserIp())
                .eqIfPresent(GatewayLogDO::getTargetServer, reqVO.getTargetServer())
                .eqIfPresent(GatewayLogDO::getMethod, reqVO.getMethod())
                .betweenIfPresent(GatewayLogDO::getRequestTime, reqVO.getRequestTime());
        if (Boolean.TRUE.equals(reqVO.getStatus())) {
            query.eq(GatewayLogDO::getCode, "200");
        } else if (Boolean.FALSE.equals(reqVO.getStatus())) {
            query.ne(GatewayLogDO::getCode, "200");
        }
        query.orderByDesc(GatewayLogDO::getCreateTime); // 降序
        return selectPage(reqVO, query);
    }
}
